﻿//
//  Windows_libc
//
//  Created by  cc_team(陈旭，陈曦) qq:511272827.
//  Copyright 2011 cc_team. All rights reserved.
//
#ifndef CC_STDLIB_H
#define CC_STDLIB_H

typedef unsigned int size_t;
#define MAX_PATH 260

// swap two numbers
#define SWAP(a, b)	\
		{	\
			(a) = (a) + (b);	\
			(b) = (a) - (b);	\
			(a) = (a) - (b);	\
		}

//year, month, day info
#define  DAYS_IN_COMMON_YEAR						365
#define  DAYS_IN_LEAP_YEAR							366
#define  MONTHS_IN_ONE_YEAR							12

// leap year or common year
#define  IS_LEAP_YEAR(year)		   \
	((year) % 400 == 0 || ((year) % 4 == 0 && (year) % 100 != 0) ? true : false)
#define  DAYS_IN_YEAR(year)			\
	(IS_LEAP_YEAR(year) ? 366 : 365)

#ifdef __cplusplus
#define SAFE_DELETE(p)	\
		{ delete []p; p = NULL; }
#else
#define SAFE_FREE(p)	\
		{ cc_free(p), p = NULL; }
#endif

#ifdef __cplusplus
extern "C" {
#endif

// It has something different with the standard C document.
void __cdecl cc_swab(
	char *src,
	char *dest,
	int bytes
);

int __cdecl cc_atoi(const char *str);
long __cdecl cc_atol(const char *str);
double __cdecl cc_atof(const char *str);

// If successfully, It will malloc one buffer, you should free the return pointer.
// It has something different with standard C declaration.
char * __cdecl cc_itoa(int n);
char * __cdecl cc_itoa_helper(
	int n, 
	unsigned int radix
	);

// get char value from a hex value, for example, cc_getCharFromHexValue(10)'s result is 'A'.
// by default, return the upper case char.
char cc_getCharFromHexValue(
	int n
	);

// a simple exit
void __cdecl cc_exit( 
	int status 
);

void __cdecl cc_abort( 
	void 
);

void __cdecl sleep(
	int miliseconds
);

// "ding" sound for specialized times
void __cdecl ding(
	int dingTimes
);

#ifdef _DEBUG
void __cdecl cc_assert(const char *message);
#endif

// void __cdecl cc_srand(size_t seed);

#ifdef __cplusplus
}		// extern "C"
#endif

#endif